import { AppLoginChain, Stage } from './AppLoginChain'

// 用户登录事件
function userLoginFun() {
  return new Promise<void>((resolve, reject) => {
    reject('用户未登录')
  })
}

function getUserNowInfo() {
  return new Promise<void>((resolve, reject) => {
    reject('用户未登录')
  })
}

// 事件map
const stages: Stage[] = [
  {
    name: 'userLogin',
    method: userLoginFun
  },
  {
    name: 'getUserInfo',
    method: getUserNowInfo
  }
]

// 创建状态机对象并暴露出去
export const appLifeCycle = new AppLoginChain(stages)

// 暴露 onLogin 回调方法
export function onLogin(hook: () => void) {
  return appLifeCycle.registerHooks('userLogin', hook)
}

// 暴露 onGetUserInfo 回调方法
export function onGetUserInfo(hook: () => void) {
  return appLifeCycle.registerHooks('getUserInfo', hook)
}
